import Router, { RouterContext } from 'koa-router';
import jwt from './lib/jwt';
import logger from './config/log4.config';
import bcrypt from './lib/bcrypt';
import validator from 'validator';
import { success, error } from './lib/utils';

export type Methos = keyof Router;

export type Ctx = RouterContext & {
  routerliving: YeeApi; 
  auth: Auth;
  jwt: typeof jwt;
  logger: typeof logger;
  bcrypt: typeof bcrypt;
  success: typeof success;
  error: typeof error;
  validator: typeof validator;
};

export interface Auth {
  userId: number;
  userName: string;
}

export interface Next {
  (): Promise<any>;
}

export interface ApiHandle {
  (ctx: Ctx, next?: Next): any;
}

// export interface ApiRequestQuery {
//   validata?: boolean;
//   type: 'number' | 'string';
//   default?: any;
// }
/**
 * ApiRequestQuery[0] => type['number' | 'string']
 * ApiRequestQuery[1] => default[any]
 * ApiRequestQuery[2] => validata[boolean]
 */
export type ApiRequestQuery = [ 'number' | 'string', any?, boolean?];
/**
 * ApiRequestBody[0] => type['number' | 'string']
 */
export type ApiRequestBody = [ 'number' | 'string' ];

// export interface ApiRequestBody {
//   type: 'number' | 'string';
// }

export interface YeeApi {
  path: string;
  method: Methos;
  controller: ApiHandle;
  auth?: boolean;
  comment?: string;
  query?: {
    [key: string]: ApiRequestQuery
  },
  body?: {
    [key: string]: ApiRequestBody
  }
}

export interface YeeRouter {
  prefix?: string;
  router: YeeApi[];
}


